﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Windows;
using AppToolkit.WPF.UI.Search;
using AppToolkit.WPF.Tests.Properties;

namespace AppToolkit.WPF.Tests.UI.Search
{
    [TestFixture]
    public class ErrorInfoConverterTests
    {
        private AppToolkit.WPF.UI.Search.ErrorInfoConverter _target;

        [SetUp]
        public void Setup()
        {
            _target = new AppToolkit.WPF.UI.Search.ErrorInfoConverter();
        }

        [Test]
        public void Returns_UnsetValue_in_case_wrong_argument_passed()
        {
            Assert.AreEqual(DependencyProperty.UnsetValue, _target.Convert( "", typeof(string), null, null));
        }

        [Test, ExpectedException(typeof(NotImplementedException))]
        public void ConvertBack_throws_not_implemented_exception()
        {
            _target.ConvertBack("", typeof(string), null, null);
        }

        [Test]
        public void In_case_of_error_UnsetValue_is_returned()
        {
            Assert.AreEqual(DependencyProperty.UnsetValue, _target.Convert(ErrorInfo.NoError, typeof(string), null, null));
        }

        [Test]
        public void Returns_resolved_resource_id()
        {
            //string id = _target.ResourcePrefix + Enum.GetName(typeof(ErrorInfo), ErrorInfo.FirstItemReached);
            string result = _target.Convert(ErrorInfo.FirstItemReached, typeof(string), null, null) as string;
            Assert.IsNotNullOrEmpty(result);
        }

        [Test]
        public void ResourceOverride()
        {
            string expected = Resources.SearchErrorInfo_ResultSetIsEmpty;
            _target.ResourceManager = Resources.ResourceManager;
            _target.ResourcePrefix = "SearchErrorInfo_";

            //string id = _target.ResourcePrefix + Enum.GetName(typeof(ErrorInfo), ErrorInfo.FirstItemReached);
            string result = _target.Convert(ErrorInfo.ResultSetIsEmpty, typeof(string), null, null) as string;
            Assert.AreEqual(expected, result);
        }

    }
}
